/**
 * DVN: Distributed Virtual Network Simulation Platform
 * Copyright (c) 2006-2009 Tyson Malchow <tyson.malchow@gmail.com>
 *
 * This file is part of the DVN distributed virtual network simulation
 * program.
 *
 * DVN is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * DVN is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with DVN.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _context_h
#define _context_h

#include <netinet/in.h>
#include <pthread.h>
#include <setjmp.h>

typedef struct context_provider_t {
	/** module instance data */
	struct module_instance_t * modinst;

	/** IP address of this node */
	in_addr_t address;

	/** destination logging channel */
	unsigned char log_channel;

	/** destination logging channel minimum level */
	int log_level;
} context_provider_t, *context_provider_tp;

struct context_sys_t {
	jmp_buf exit_env;
	int exit_usable;

	context_provider_tp current_context;
	struct sim_worker_t * sim_worker;

	/** static context is used for non-node calls to modules; e.g. init and uninit, for purposes
	 * really only related to snri_register_globals
	 */
	struct module_t * static_context;
};

/** global for all objects to access the context */
extern struct context_sys_t global_sim_context;

typedef void (*vci_onrecv_cb_tp)(
			int, /* socket */
			in_addr_t, /* source address*/
			int,  /*source port*/
			unsigned int, /* data length */
			char * /* data */
		);


typedef void (*dtimer_ontimer_cb_fp)(int, void *);

void context_set_worker(struct sim_worker_t *wo);
void context_execute_destroy(context_provider_tp provider);
void context_execute_init(struct module_t *module);
void context_execute_instantiate(context_provider_tp provider, in_addr_t bootstrap_addr, int argc, char* argv[]);
void context_execute_dtimer_cb(context_provider_tp provider, dtimer_ontimer_cb_fp cb, int timer_id, void * cb_arg);
void context_execute_vci_onrecv(context_provider_tp provider, vci_onrecv_cb_tp cb, int socket, in_addr_t source_address,
		int source_port, unsigned int data_size, char * data);

#endif
